package com.woniu.adopt_web.service;

import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.mail.javamail.MimeMessageHelper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import javax.mail.MessagingException;
import javax.mail.internet.MimeMessage;


@Service
public class EmailService {
    @Resource
    private JavaMailSender jms;

    public boolean sendHtml(String sender, String receiver, String subject, String content) {
        MimeMessage message = jms.createMimeMessage();
        try {
            MimeMessageHelper helper = new MimeMessageHelper(message, true,"UTF-8");
            //发送方
            helper.setFrom(sender);
            //接收方
            helper.setTo(receiver);
            //邮件主题
            helper.setSubject("欢迎注册-蜗牛领养平台");
            //邮件内容
//            String content="<h1>尊敬的用户，您好！</h1><br />我们即将创建好您的 蜗牛领养平台 账户，<br /><h3>验证码："+emailCode+"</h3>";


            helper.setText(content, true);
            jms.send(message);
            return true;
        } catch (MessagingException e) {
            e.printStackTrace();
            return false;
        }
    }
}
